﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Incendios0_1.sms
{
    /// <summary>
    /// Interaction logic for lookfor_contact.xaml
    /// </summary>
    public partial class lookfor_contact : Window
    {
        private Contacts rContact;
        private bool cancel;

        public lookfor_contact()
        {
            InitializeComponent();
            rContact = null;
            cancel = true;
        }

        private void deletecontact_Click(object sender, RoutedEventArgs e)
        {
            searchContact();
        }

        private void searchContact()
        {
            Contacts contact = ContactControler.SearchContactByPhone(textBox1.Value.ToString());
            if (contact == null)
            {
                Microsoft.Windows.Controls.MessageBox.Show("El contacto no existe", "No encontrado", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                rContact = contact;
                cancel = false;
                this.Close();
            }
        }

        private void Canceldeletecontact_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        internal Contacts Search()
        {
            this.ShowDialog();
            return rContact;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (cancel)
                rContact = null;
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                searchContact();
        }
    }
}
